import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString, IsOptional } from 'class-validator';
import { PageDto } from 'src/common/dto/dto';
import { Gender, Status } from 'src/dictionaries/index.enum';
import { FindOperator } from 'typeorm';
export class GetUserPage extends PageDto {
  @ApiPropertyOptional({
    type: Number,
    name: 'id',
    description: 'id',
  })
  public readonly id: number;

  @ApiPropertyOptional({
    type: String,
    name: 'email',
    description: '邮箱',
  })
  public readonly email: string;

  @ApiPropertyOptional({
    type: String,
    name: 'phone',
    description: '电话号码',
  })
  public readonly phone: string;

  @ApiPropertyOptional({
    name: 'gender',
    description: '性别',
    enum: Gender
  })
  public readonly gender: Gender;

  @ApiPropertyOptional({
    type: String,
    name: 'username',
    description: '用户名',
  })
  public readonly username: FindOperator<string>;
  @ApiPropertyOptional({
    type: String,
    name: 'account',
    description: '账号',
  })
  public readonly account: FindOperator<string>;
  @ApiPropertyOptional({
    name: 'status',
    description: '用户状态',
    enum: Status
  })
  public readonly status: Status;
}

export class CreateUserDto {
  @ApiProperty({ example: 'john@example.com', description: '用户邮箱' })
  @IsEmail()
  @IsNotEmpty()
  email: string;

  @IsNotEmpty({ message: '用户账号不能为空' })
  @IsString()
  @ApiProperty({
    type: String,
    name: 'account',
    description: '用户账号',
  })
  public readonly account: string;


  @ApiProperty({ example: 'John Doe', description: '用户姓名' })
  @IsString()
  @IsNotEmpty()
  username: string;

  @ApiProperty({ example: '手机号', description: '用户手机号' })
  @IsString()
  @IsNotEmpty()
  phone: string;

  @ApiProperty({ example: '头像URL', description: '用户头像URL' })
  @IsString()
  @IsOptional()
  avatar: string;

  @IsNotEmpty({ message: '密码不能为空' })
  @ApiProperty({
    type: String,
    name: 'password',
    description: '密码',
  })
  public readonly password: string;
}
export class UpdatePassWordDto {
  @IsNotEmpty({ message: '登录密码不能为空' })
  @ApiProperty({
    type: String,
    name: 'old_password',
    description: '登录密码',
  })
  public readonly old_password: string;

  @IsNotEmpty({ message: '新密码不能为空' })
  @ApiProperty({
    type: String,
    name: 'new_password',
    description: '新密码',
  })
  public readonly new_password: string;
}

/** 登录 */
export class LoginDto {
  @IsNotEmpty({ message: '用户名不能为空' })
  @ApiProperty({
    type: String,
    name: 'username',
    description: '用户名',
  })
  public readonly username: string;

  @IsNotEmpty({ message: '密码不能为空' })
  @ApiProperty({
    type: String,
    name: 'password',
    description: '密码',
  })
  public readonly password: string;
}

export class UpdateUserInfoDto {
  @IsNotEmpty({ message: '用户昵称不能为空' })
  @ApiProperty({
    type: String,
    name: 'username',
    description: '用户昵称',
  })
  public readonly username: string;

  @ApiPropertyOptional({
    type: String,
    name: 'phone',
    description: '电话号码',
  })
  public readonly phone: string;

  @ApiPropertyOptional({
    type: String,
    name: 'avatar',
    description: '头像',
  })
  public readonly avatar: string;

  @ApiPropertyOptional({
    type: String,
    name: 'hometown',
    description: '用户籍贯',
  })
  public readonly hometown: string;

  @ApiPropertyOptional({
    type: String,
    name: 'address',
    description: '地址',
  })
  public readonly address: string;

  @ApiPropertyOptional({
    name: 'gender',
    description: '性别',
    enum: Gender
  })
  public readonly gender: Gender;
}